import toolMgr from '@/biz/base/tool.js'
import dt from '@dt/dt'
import incentiveMgr from '@/biz/bonus/incentive'
let _this = null

function getrepeat(val) {
  let params = {
    housesId: dt.buildInfo().housesId,
    name: val
  }
  return new Promise((resolve, reject) => {
    incentiveMgr.selectBonusStimulateRepeat(params).then((res) => {
      resolve(res)

    })
  })

}

function options(vm, isLockTime) {
  _this = vm
  return [
    [{
      title: '在销激励名称',
      key: 'bonusName',
      placeholder: '请输入在销激励名称',
      input: {
        type: 'text',
        blur: (val) => {
          if (val != '') {
            getrepeat(val).then(res => {
              if (!res) {
                _this.$Message.warning('在销激励名称不能重复。')
                _this.info.bonusName = ''
              }
            })
          }
        }
      },
      rules: [{
        required: true,
        message: '请输入在销激励名称',
        trigger: 'blur'
      }]
    }],
    [{
      key: 'bonusMonth',
      title: '发放月份',
      placeholder: '请选择发放月份',
      disabled: isLockTime != null ? isLockTime : true,
      date: {
        type: 'month'
      },
      rules: [{
        required: true,
        message: '请选择发放月份',
        trigger: 'blur'
      }]
    }],
    [{
      key: 'headerType',
      title: '在销激励类型',
      placeholder: '请选择在销激励类型',
      minWidth: 220,
      select: {
        options: dt.dictInfo().bonusHeaderTypeTwo
      },
      rules: [{
        required: true,
        message: '请选择在销激励类型',
        trigger: 'blur'
      }]
    }, ]
  ]
}

export default {
  options
}